package com.joyoung.sweep.base;

import android.app.Application;
import android.content.Context;
import android.util.Log;

import com.joyoung.sweep.config.Cons;
import com.joyoung.sweep.model.BaseResult;
import com.joyoung.sweep.utils.Net.JYHttpDS1;
import com.joyoung.sweep.utils.SPUtils;

/**
 * @author: ThinkPad
 * date: 2021/4/12
 * desc:  Application
 */
public class JoyoungApplication extends Application {
    private static Context appContext;
    private static JoyoungApplication thiz;
    @Override
    public void onCreate() {
        super.onCreate();
        appContext = this;
        thiz=this;
    }

    public static Context getAppContext() {
        return appContext;
    }

    public static JoyoungApplication getApplication() {
        return thiz;
    }

    public void getToken() {
        new JYHttpDS1().getToken(new JYHttpDS1.JoyoungCallBack<BaseResult<String>>() {
            @Override
            public void Success(BaseResult<String> stringBaseResult) {
                Log.i("App", "Success: "+stringBaseResult.toString());
                if (stringBaseResult.getCode() == 0) {
                    if (stringBaseResult.getData() != null && !stringBaseResult.getData().isEmpty()) {
                        SPUtils.put(getApplicationContext(), Cons.SP_APP_AUTHOR_TOKEN, stringBaseResult.getData());
                    }
                }
            }

            @Override
            public void failed(String msg) {
                Log.i("App", "get token failed : ---->>>" + msg);
            }
        });
    }
}
